package com.cytech.cookielearn.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class UserController {
    @GetMapping("/username")
    public String getUsername(HttpServletRequest request, HttpServletResponse response) {
        Cookie cookie = new Cookie("company", "Cytech");
        Cookie cookie2 = new Cookie("teacher", "haojq");

//        cookie.setPath("/aa/bb");
//        cookie2.setPath("/cc");

        //谁知Cookie的有效期，单位为秒
        // 该值大于0，或者不设置，会将cookie存在浏览器的缓存，关闭浏览器即消失

//        cookie.setMaxAge(60*60);
//        cookie2.setMaxAge(60*60*24);

        response.addCookie(cookie);
        response.addCookie(cookie2);
        return "haojq";
    }
}

